package tools;


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:
 * @author
 * @version 1.0
 */
public class StockProcess extends TextProcess {

  private JTextField stockSymbol;
  private JTextField stockClass;
  private JButton getUrlButton;
  /**
   * This filter works with the file chooser to limit the files shown.<p>
   */
  private javax.swing.filechooser.FileFilter xslFilter =
    new javax.swing.filechooser.FileFilter() {

      public boolean accept( java.io.File pathname ) {
        return pathname.isDirectory() || pathname.getName().endsWith( ".xsl" );
      }


      public String getDescription() {
        return "eXtensible Stylesheet Language (*.xsl)";
      }
    };


  public StockProcess() {
    addChoosableFileFilter( xslFilter );
    setName( "Stock" );
    stockSymbol = new JTextField( 8 );
    stockClass = new JTextField( 8 );
    getUrlButton = new JButton( "Get URL" );

    JPanel northPanel = new JPanel( new BorderLayout( 3, 0 ) );
    northPanel.setBorder( BorderFactory.createEmptyBorder( 2, 3, 3, 3 ) );

    JPanel fieldPanel = new JPanel( new GridBagLayout() );
    GridBagConstraints gbc =
      new GridBagConstraints( 0, 0, 1, 1, 0, 0,
                              GridBagConstraints.WEST,
                              GridBagConstraints.NONE,
                              new Insets( 1, 0, 1, 0 ), 5, 0 );

    fieldPanel.add( new JLabel( "Symbol" ), gbc );

//    JPanel symbolFieldPanel = new JPanel( new BorderLayout() );
    gbc.gridx += 1;
    fieldPanel.add( stockSymbol, gbc );
    gbc.gridx = 0;
    gbc.gridy += 1;
    fieldPanel.add( new JLabel( "Class" ), gbc );
    gbc.gridx += 1;
    fieldPanel.add( stockClass, gbc );
    northPanel.add( fieldPanel, BorderLayout.WEST );

    add( northPanel, BorderLayout.NORTH );

    JPanel buttonPanel = new JPanel( new GridLayout() );
    buttonPanel.add( getUrlButton );
    JPanel southPanel = new JPanel( new FlowLayout( FlowLayout.CENTER ) );
    southPanel.add( buttonPanel );
    add( southPanel, BorderLayout.SOUTH );

    getUrlButton.addActionListener( new ActionListener() {

                                    public void actionPerformed( ActionEvent e ) {
                                      getUrlPerformed( e );
                                    }
                                  } );
  }


  protected void getUrlPerformed( ActionEvent e ) {
    fireActionPerformed( new ActionEvent( this, ActionEvent.ACTION_PERFORMED,
                                          e.getActionCommand() ) );
  }


  public String getSymbol() {
    return stockSymbol.getText();
  }


  public String getSymbolClass() {
    return stockClass.getText();
  }
}